package com.briup.day21;

/**
 * @author ThinkBook
 */
public class Test01_Circle {
    public static void main(String[] args) {
        //1.实例化泛型类对象 【菱形泛型】
        Circle<Integer,Double> c1 = new Circle<>();

        //2.调用方法
        c1.setX(5);
        c1.setRadius(2.5);

        System.out.println(c1);

        c1.disp(10);

        //调用泛型方法
        c1.show(15);    // U -> Integer
        c1.show(5.5);   // U -> Double
        c1.show(7.8F);  // U -> Float
        c1.show("hello");   // U -> String

    }
}

//泛型类定义
class Circle<T,E> {
    private T x;
    private T y;
    private E radius;

    //构造方法
    public Circle() {
    }
    public Circle(T x, T y, E radius) {
        this.x = x;
        this.y = y;
        this.radius = radius;
    }

    //get|set方法
    public T getX() {
        return x;
    }
    public void setX(T x) {
        this.x = x;
    }
    public T getY() {
        return y;
    }
    public void setY(T y) {
        this.y = y;
    }
    public E getRadius() {
        return radius;
    }
    public void setRadius(E radius) {
        this.radius = radius;
    }

    //普通方法
    public void disp(T t) {
        System.out.println("in disp,t: " + t);
    }

    //定义泛型方法
    public <U> void show(U u) {
        System.out.println("in show, u: " + u);
    }

    @Override
    public String toString() {
        return "Circle{" +
                "x=" + x +
                ", y=" + y +
                ", radius=" + radius +
                '}';
    }
}

